package zhoug.demo.zui.ui;

import android.os.Bundle;

import zhoug.common.content.FileType;
import zhoug.common.utils.FileUtils;
import zhoug.common.utils.ToastUtils;
import zhoug.common.utils.file.IFile;
import zhoug.zui.ZUIFilePreview;
import zhoug.demo.zui.R;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * @Author: zhoug
 * @Date: 2024-07-17
 * @Description:
 */
public class ZUIFilePreviewActivity  extends AppCompatActivity {

    private ZUIFilePreview filePreview1;
    private ZUIFilePreview filePreview2;
    private ZUIFilePreview filePreview3;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_filereview);
        findViews();

        filePreview1.setFiles(getFiles());
        filePreview1.setDeleteEnable(false);

        filePreview2.setFiles(getFiles());
        filePreview2.setDeleteEnable(true);
        filePreview2.setOnDeleteListener(new ZUIFilePreview.OnDeleteListener() {
            @Override
            public void onDeleteFile(ZUIFilePreview view, int position, IFile file) {
                ToastUtils.toastLong("删除"+file.getFileName());
            }
        });

        filePreview3.setFiles(getFiles());
        filePreview3.setDeleteEnable(false);
    }

    private List<MyFile> getFiles(){
        File externalRoot = FileUtils.getExternalRoot();
        List<MyFile> myFiles=new ArrayList<>();
        myFiles.add(new MyFile(FileType.IMAGE,"http://192.168.0.32/images/image2.jpg",".jpg","图片1"));
        myFiles.add(new MyFile(FileType.IMAGE,"https://wxls-cms.oss-cn-hangzhou.aliyuncs.com/online/2024-04-18/1233123.jpg",".jpg","图片1"));
        myFiles.add(new MyFile(FileType.IMAGE,null,".jpg","图片1"));

        myFiles.add(new MyFile(FileType.IMAGE,"https://wxls-cms.oss-cn-hangzhou.aliyuncs.com/online/2024-04-18/218da022-f4bf-456a-99af-5cb8e157f7b8.jpg",".jpg","图片1"));
        myFiles.add(new MyFile(FileType.IMAGE,"https://lmg.jj20.com/up/allimg/4k/s/02/210924231A341I-0-lp.jpg",".jpg","图片2"));
        myFiles.add(new MyFile(FileType.IMAGE,"https://cmsimg.cbg.cn/2021/10/23/969b2472a7f5489b8972cc905fa31d06.jpeg",".jpeg","图片3"));
        myFiles.add(new MyFile(FileType.IMAGE,"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage109.360doc.com%2FDownloadImg%2F2021%2F11%2F0215%2F233196966_2_20211102030154677&refer=http%3A%2F%2Fimage109.360doc.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1723789454&t=7c56fdf9e9771be4e9cecae6707e6397",".jpg","图片4"));
        myFiles.add(new MyFile(FileType.IMAGE,"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage109.360doc.com%2FDownloadImg%2F2021%2F09%2F1409%2F230310966_1_20210914091333446&refer=http%3A%2F%2Fimage109.360doc.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1723789454&t=e024c3f28a801448218686f8f5395d90",".jpg","图片5"));
        myFiles.add(new MyFile(FileType.IMAGE,"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201708%2F24%2F20170824191137_SeXcY.png&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1723789556&t=f3d300ead445280f98c4f2340cb08846",".png","图片6"));
        myFiles.add(new MyFile(FileType.IMAGE,new File(externalRoot,"0相册/2018-10-14_17_56_07.jpg").getAbsolutePath(),".jpg","本地图片"));
        myFiles.add(new MyFile(FileType.VIDEO,"https://v-cdn.zjol.com.cn/276982.mp4",".mp4","在线视频1"));
        myFiles.add(new MyFile(FileType.VIDEO,"https://v-cdn.zjol.com.cn/276984.mp4",".mp4","在线视频2"));
        myFiles.add(new MyFile(FileType.VIDEO,new File(externalRoot,"0视频/QQ空间视频_20190205190803.mp4").getAbsolutePath(),".mp4","本地视频"));
        myFiles.add(new MyFile(FileType.AUDIO,new File(externalRoot,"0音乐/爱如潮水-张学友.mp3").getAbsolutePath(),".mp3","音频"));
        myFiles.add(new MyFile(FileType.PDF,new File(externalRoot,"0相册/011002300411-64937955.pdf").getAbsolutePath(),".pdf","PDF"));
        myFiles.add(new MyFile(FileType.WORD,new File(externalRoot,"1/word1.doc").getAbsolutePath(),".doc","word"));
        myFiles.add(new MyFile(FileType.EXCEL,new File(externalRoot,"1/excel1.xls").getAbsolutePath(),".xls","xls"));
        myFiles.add(new MyFile(FileType.TXT,new File(externalRoot,"1/text.txt").getAbsolutePath(),".txt","txt"));
        return myFiles;
    }

    private void findViews() {
        filePreview1 = findViewById(R.id.filePreview1);
        filePreview2 = findViewById(R.id.filePreview2);
        filePreview3 = findViewById(R.id.filePreview3);
    }

    private class MyFile implements IFile{
        private int fileType;
        private String realUrl;
        private String fileSuffix;
        private String fileName;

        public MyFile(int fileType, String realUrl, String fileSuffix, String fileName) {
            this.fileType = fileType;
            this.realUrl = realUrl;
            this.fileSuffix = fileSuffix;
            this.fileName = fileName;
        }

        @Override
        public int getFileType() {
            return fileType;
        }

        @Override
        public String getRealUrl() {
            return realUrl;
        }

        @Override
        public String getFileSuffix() {
            return fileSuffix;
        }

        @Override
        public String getFileName() {
            return fileName;
        }
    }


}
